import { roomOwner } from "../tools/baseTools";
import memoryData from "../tools/memoryData"
import showInfo from "../tools/showInfo";

import creepManager from "./rule/creepManager";
import eventManager from "./event/eventManager";
import scheduleManager from './scheduleManager'
import progressManager from './progressManager'
import mountManager from "./mount/mountManager";
import taskManager from "./task/taskManager";
import autoBuildManager from "./autoBuild/autoBuildManager";

export default {
    baseInit: function () {
        // 大型重构才调用这个方法清空内存
        Object.keys(Memory).map(key => delete Memory[key])
        return this
    },
    init: () => {
        Memory.rooms = {}
        mountManager.init()
        eventManager.init()
        Object.keys(Game.rooms).map(roomName => {
            let params = {
                room: Game.rooms[roomName],
                roomName: roomName,
                owner: roomOwner(roomName)          // 房间归属
            }
            // 根据房间进行的任务运行
            memoryData.init(params)
            progressManager.init(params)            // 游戏进程管理器
            taskManager.init(params)                // 任务管理器
            autoBuildManager.init(params)
        })
        memoryData.initData()
        scheduleManager.init()
    },
    run: () => {
        Object.keys(Game.rooms).map(roomName => {
            let params = {
                room: Game.rooms[roomName],
                roomName: roomName,
                roomMemory: Memory.rooms[roomName],
                owner: roomOwner(roomName)  // 房间归属
            }
            // 根据房间进行的任务运行
            autoBuildManager.run(params)    // 要放到room.run前边，eventManager.run后边，因为房间的isRuning控制自动建造模块的运行
            params.room.run(params)
            showInfo.run(params)
        })
        eventManager.run()      // 事件管理器
        scheduleManager.run()   // 定时任务管理器
        progressManager.run()   // 游戏进程管理器
        creepManager.run()      // creep管理器
    }
}